%Question 5
%**************************************************************
%Use a multi-layer perceptron to classify the data
%Using a multi-layer perceptron
%*************************************************************
load('imdata.mat', 'x','y');
xtraining  = double(x(1:1000,:));
ytraining = double(y(1:1000,:));

load('imtestdata.mat');
test = double(x(1:1000,:));


%Perform 4-fold cross validation

% Set up network parameters.
%Set the num of inputs and outputs
numInputs = size(xtraining,2);
numHidden = 5;
numOutputs = 1; %Attribute 14
alpha = 0.01;			% Coefficient of weight-decay prior. 

% Create and initialize network weight vector.

net = mlp(numInputs, numHidden, numOutputs, 'linear', alpha);

% Set up vector of options for the optimiser.

options = zeros(1,18);
options(1) = 1;			% This provides display of error values.
options(14) = 50;		% Number of training cycles. 

% Train using scaled conjugate gradients.
[net, options] = netopt(net, options, xtraining, ytraining, 'scg');

% Plot the data, the original function, and the trained network function.
yvalid = mlpfwd(net, test);
Nt = size(test,1);
%rmsError = sqrt(1/Nt * sum((yvalid - test).^2))


%**************************************************************
